<!DOCTYPE html>
<html>
<head>
    <title>{$platform.name}</title>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>

    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <!--    <script src="/static/js/framework-ui.js"></script>-->
    <!--    <script src="/static/js/framework-clientdata.js"></script>-->

    <!--弹框js-->
    <script src="/static/js/yii.js"></script>

    <!--引用layui弹框插件-->
    <script src="/static/layui/layui.all.js"></script>
    <script src="/static/layui/layui.js"></script>
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/lay/modules/layer.js"></script>


    <!--    配置select多选相关-->
    <!--    <script src="/static/layui/dist/xm-select.js"></script>-->


        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}


    <script src="/static/js/jquery-2.1.1.js"></script>
    <link rel="stylesheet" href="https://cache.amap.com/lbs/static/main.css"/>
    <script type="text/javascript" src='//webapi.amap.com/maps?v=2.0&key=1b5095aca8acff10518bf883f334b2ad&plugin=AMap.ToolBar'></script>
    <script src="//webapi.amap.com/ui/1.1/main.js?v=1.1.1"></script>

</head>
<body>
<style>
    html, body{background-color:#FFF!important;}
    .modal-body{background-color:#fff;padding:15px}
    .page-header{margin-top:15px!important;}
    .geographic input{width:100px!important;float: left;margin-right:15px;}
</style>

<div class="modal-body">


    <div class="page-header">
        <h3>编辑小区</h3>
    </div>

    <form class="form-horizontal layui-form">

        <div class="form-group">
            <label class="col-sm-1 control-label">*所属区域:</label>
            <div class="col-sm-2">
                <select name="provinceId" lay-verify="provinceId"  lay-filter="provinceId" class="select">
                    <option value="">请选择</option>
                    {volist name="region" id="vo"}
                    <option value="{$vo.id}" {if condition="$detail['provinceId'] eq $vo['id']"} selected {/if} >{$vo.name}</option>
                    {/volist}
                </select>
            </div>

            <div class="col-sm-2">
                <select name="fcityId" lay-verify="fcityId"  lay-filter="fcityId" class="select">
                    <option>请选择</option>
                    {volist name="fcity" id="vo"}
                    <option value="{$vo.id}" {if condition="$detail['fcityId'] eq $vo['id']"} selected {/if} >{$vo.name}</option>
                    {/volist}
                </select>
            </div>

            <div class="col-sm-2">
                <select name="cityRegionId" lay-verify="cityRegionId"  lay-filter="cityRegionId" class="select">
                    <option>请选择</option>
                    {volist name="cityRegion" id="vo"}
                    <option value="{$vo.id}" {if condition="$detail['cityRegionId'] eq $vo['id']"} selected {/if} >{$vo.name}</option>
                    {/volist}
                </select>
            </div>

        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">*街道名称:</label>
            <div class="col-sm-2">
                <select name="streetCode" lay-verify="streetCode"  lay-filter="streetCode" class="select">
                    <option>请选择街道</option>
                    {volist name="streetCode" id="vo"}
                    <option value="{$vo.id}" {if condition="$detail['streetCode'] eq $vo['id']"} selected {/if} >{$vo.name}</option>
                    {/volist}
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">*地址:</label>
            <div class="col-sm-8">
                <textarea  name="address"  placeholder="地址" class="layui-textarea" lay-verify="content">{$detail.address}</textarea>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">*地图标识:</label>
            <div class="col-sm-8 geographic">
                <input type="text" class="form-control" name="lng" value="{$detail.lng}" >
                <input type="text" class="form-control" name="lat" value="{$detail.lng}" >
                <a class="btn btn-default js_coordinate">选择坐标</a>
            </div>
        </div>


        <div class="form-group">
            <label class="col-sm-1 control-label">*小区编号:</label>
            <div class="col-sm-8">
                <input type="text" disabled class="form-control" name="propertyNo" value="{$detail.propertyNo}" placeholder="自动生成不可编辑" >
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">*小区名称:</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" name="propertyName" value="{$detail.propertyName}" placeholder="小区名称" >
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">*类型:</label>
            <div class="col-sm-3">
                <select name="type">
                    <!--                    <option value="0">请选择</option>-->
                    {volist name="condo" id="vo" key="k"}
                    <option value="{$k}" {if condition="$detail['type'] eq $k"} selected {/if}>{$vo}</option>
                    {/volist}
                </select>
            </div>

            <label class="col-sm-2 control-label">*能否修改人脸:</label>
            <div class="col-sm-3">
                <select name="entryFace">
                    <!--                    <option value="0">请选择</option>-->
                    {volist name="status" id="vo" key="k"}
                    <option value="{$k}" {if condition="$detail['entryFace'] eq $k"} selected {/if}>{$vo}</option>
                    {/volist}
                </select>
            </div>

        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">*物业热线电话:</label>
            <div class="col-sm-3">
                <input type="number" class="form-control"  value="{$detail.hotline}" name="hotline" placeholder="物业热线电话" >
            </div>

            <label class="col-sm-2 control-label">*物业热线短号:</label>
            <div class="col-sm-3">
                <input type="number" class="form-control"  value="{$detail.shortNo}" name="shortNo" placeholder="物业热线短号" >
            </div>

        </div>

        <div class="form-group">
            <label class="col-sm-1 control-label">是否付费区:</label>
            <div class="col-sm-3">
                <select name="isPay">
                    <!--                    <option value="0">请选择</option>-->
                    {volist name="status" id="vo" key="k"}
                    <option value="{$k}" {if condition="$detail['isPay'] eq $k"} selected {/if}>{$vo}</option>
                    {/volist}
                </select>
            </div>
        </div>

        <input type="hidden" name="id" value="{$detail.id}">
    </form>
</div>
<div class="add_button">

    <div class="form-group">
        <label  class="col-sm-1 control-label"></label>
        <div class="col-sm-8">
            <a type="button" class="btn btn-default btn-sm" href="{:URL('admin/community/index')}" >取消</a>
            <button type="button" class="btn btn-primary btn-sm" id="newsave" >保存</button>
        </div>
    </div>
</div>


<script>

    var newModal = new yii.modal();
    //选择坐标界面
    $(".js_coordinate").click(function () {
        var lng = $('input[name="lng"]').val();
        var lat = $('input[name="lat"]').val();
        $(newModal.getid()).show();
        newModal.initialization({
            url: "{:URL('common/Common/map')}",
            type: "post",
            data:{
                type:'detail',
                lng:lng,lat:lat
            }
        });
    });

    //赋值信息
    newModal.on("newmap",function(data){
        var lng=$(newModal.getid()).find("#lng").val();
        var lat=$(newModal.getid()).find("#lat").val();
        $('input[name="lng"]').val(lng);
        $('input[name="lat"]').val(lat);
    });


    layui.use(['form','layedit','tree','util'], function() {
        var form = layui.form
            , layer = layui.layer;
        var layedit = layui.layedit;
        var  tree = layui.tree;
        var util = layui.util;


        //触发二级联动
        form.on('select(provinceId)', function (data) {
            //触发联动
            var level = 2;
            var id = data.value;
            $.ajax({
                type:'post',
                url:"{:URL('common/Common/cityApi')}",
                data:{level:level,id:id},
                dataType:'JSON',
                success:function (res) {
                    var arr = res.data;
                    var html = '<option value="">请选择</option>';
                    $.each(arr, function(e,v){
                        html +='<option value="'+v.id+'">'+v.name+'</option>';
                    });
                    $('select[name="fcityId"]').html(html);
                    $('select[name="cityRegionId"]').html('<option value="">请选择</option>');
                    $('select[name="streetCode"]').html('<option value="">请选择</option>');
                    form.render('select');
                },
                error:function (res) {
                }
            });
        });


        //触发三级联动
        form.on('select(fcityId)', function (data) {
            //触发联动
            var level = 3;
            var id = data.value;
            $.ajax({
                type:'post',
                url:"{:URL('common/Common/cityApi')}",
                data:{level:level,id:id},
                dataType:'JSON',
                success:function (res) {
                    var arr = res.data;
                    var html = '<option value="">请选择</option>';
                    $.each(arr, function(e,v){
                        html +='<option value="'+v.id+'">'+v.name+'</option>';
                    });
                    $('select[name="cityRegionId"]').html(html);
                    $('select[name="streetCode"]').html('<option value="">请选择</option>');
                    form.render('select');
                },
                error:function (res) {
                }
            });
        });

        //触发四级联动
        form.on('select(cityRegionId)', function (data) {
            //触发联动
            var level = 4;
            var id = data.value;
            $.ajax({
                type:'post',
                url:"{:URL('common/Common/cityApi')}",
                data:{level:level,id:id},
                dataType:'JSON',
                success:function (res) {
                    var arr = res.data;
                    var html = '<option value="">请选择</option>';
                    $.each(arr, function(e,v){
                        html +='<option value="'+v.id+'">'+v.name+'</option>';
                    });
                    $('select[name="streetCode"]').html(html);
                    form.render('select');
                },
                error:function (res) {
                }
            });
        });




        $("#newsave").click(function () {
            var data = $("form").serializeArray();
            $.ajax({
                type:'post',
                url:"{:URL('admin/community/addcommunity')}",
                data:data,
                dataType:'JSON',
                success:function (res) {
                    if(res.code!=0){
                        layer.alert(res.msg);
                    }else{
                        window.location.href = "{:URL('admin/community/index')}";
                    }
                },
                error:function (res) {

                }
            });

        })



        layui.form.render('select');
        form.render();


    });
</script>

</body>
</html>